//
//  YCNavViewController.m
//  YCVillageDoctor
//
//  Created by zhangxiaoliang on 2017/6/7.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "YCNavViewController.h"
#import "UIImage+Resizable.h"

@interface YCNavViewController ()

@end

@implementation YCNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //修改状态栏字体原色
    [UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleLightContent;
    [self.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.shadowImage = [[UIImage alloc] init];
    [self.navigationBar setBackgroundImage:
     [UIImage imageNamed:@"矩形-4"] forBarMetrics:UIBarMetricsDefault];
    
    NSMutableDictionary *titleAttributes = [NSMutableDictionary dictionary];
    titleAttributes[NSForegroundColorAttributeName] = [UIColor whiteColor];
    titleAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    [self.navigationBar setTitleTextAttributes:titleAttributes];
    // Do any additional setup after loading the view.
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 这时push进来的控制器viewController，不是第一个子控制器（不是根控制器）
        /* 自动显示和隐藏tabbar */
        viewController.hidesBottomBarWhenPushed = YES;
        
        
        /* 设置导航栏上面的内容 */
        // 设置左边的返回按钮
        
        UIImage *img= [UIImage imageNamed:@"back"];
        img= [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UIButton *navBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 5, 40, 30)];
        
        navBtn.imageEdgeInsets= UIEdgeInsetsMake(0, -30, 0, 0);
        [navBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
        [navBtn setImage:img forState:UIControlStateNormal];
        
        
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:navBtn];
        
    }
    
    
    [super pushViewController:viewController animated:animated];
}

- (void)backClick
{
    // 因为self本来就是一个导航控制器，self.navigationController这里是nil的
    [self popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
